from my_package import my_time
def menu():
    print('*' * 30)
    print('''欢迎使用日记本：
    1. 写日记
    2. 读日记
    0. 退出''')
    print('*' * 30)


def write_diary():
    filename = 'diary.txt'
    file = open(filename, mode='a', encoding='utf8')
    file.write('pyrjb\n')
    content = input('请输入日记本内容：')
    file.writelines([my_time.get_time() + '\n', content + '\n'])
    file.close()
    return True


def read_diary(date = '-1'):
    filename = 'diary.txt'
    file = open(filename, mode='r', encoding='utf8')
    content = file.read()
    file.close()
    if date != '-1':
        content_list = content.split('pyrjb\n')
        for i in content_list:
            if date in i:
                print(i)
                return True
        return False
    else:
        content = content.replace('pyrjb\n', '')
        print(content)
        return True


def quit():
    print('感谢使用日记本，下次再见！')


menu()

while True:
    option = int(input('请输入你的选择：'))
    if option == 1:
        if write_diary():
            print('内容保存成功！')
    elif option == 2:
        date = input('请输入日期查询对应日记（输入-1查询全部）：')
        if read_diary(date):
            print('内容已加载完毕！')
        else:
            print('未查询到，请重试！')
    elif option == 0:
        quit()
        break
    else:
        print('请输入正确选项！')